package com.example.myapplication1

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class ListActivity : AppCompatActivity() {



       private val book = arrayListOf<Book>()



        override fun onCreate(savedInstanceState: Bundle?) {

            super.onCreate(savedInstanceState)

            setContentView(R.layout.activity_list)



            initData()

            val recycler = findViewById<RecyclerView>(R.id.recycler)

            recycler.layoutManager = LinearLayoutManager(this)

            recycler.adapter = BookAdapter(book)



        }



        private fun initData() {



            for( i in 0..10) {



                book.add(Book().apply {

                    name = "《一千零一夜》"

                    description =

                        "非常好看！"

                    avatar = R.mipmap.p2

                })



                book.add(Book().apply {

                    name = "《假如给我三天光明》"

                    description =

                        "剧情跌宕起伏。"

                    avatar = R.mipmap.p3

                })

                book.add(Book().apply {

                    name = "《爱的教育》"

                    description =

                        "写出了真情实感，非常感人。"

                    avatar = R.mipmap.p4

                })

            }



        }

    }

